#include <stdio.h>
#include <assert.h>

#ifndef _MSC_VER
#include <xilinx.h>
#else
#include <time.h>
#endif

#include "Simulator.h"

static void usage(const int argc, const char** argv)
{
	printf("usage:\n%s <cycles>\n", argv[0]);
	exit(0);
}

static void getArguments(const int argc, const char** argv)
{
	// check number of arguments
	if(argc != 2)
	{  
		printf("invalid number of arguments\n");
		usage(argc, argv);
	}

	Simulator::Cycles = atoi(argv[1]);

	// check number of cycles
	if(Simulator::Cycles <= 0) 
	{
		printf("invalid number of cycles: %s\n", argv[1]);
		usage(argc, argv);
	}
}

int main(const int argc, const char** argv)
{

#ifdef _MSC_VER
	// timing code variables
	clock_t tv1, tv2;
	double time;
	tv1 = clock();

	getArguments(argc, argv);
#else
  Simulator::Cycles = 24; // Set no. cycles here for FPGA execution
#endif 

	Simulator::Initialize();
	Simulator::Run();

#ifdef _MSC_VER
	// calculate and print elapsed time
	tv2 = clock();
	time = (tv2 - tv1) /(CLOCKS_PER_SEC / (double)1000.0);

	printf("time elapsed %f ms\n", time);	
#endif

	return 0;
}
